package com.rdc.example.service.impl;

import com.rdc.example.bean.Result;
import com.rdc.example.dao.PlayCountDao;
import com.rdc.example.dao.SongDao;
import com.rdc.example.dao.impl.PlayCountDaoImpl;
import com.rdc.example.dao.impl.SongDaoImpl;

public class PlayCountServiceImpl implements com.rdc.example.service.PlayCountService {
    PlayCountDao playCountDao=new PlayCountDaoImpl();
    SongDao songDao = new SongDaoImpl();

    @Override
    public Result addPlayCount(Integer userId, Integer songId) throws Exception {
        if (userId == null || songId == null) {
            return Result.fail("songId或userId为空", null);
        }

        if (!playCountDao.checkSongPlayCount(userId, songId)) {
          //没有播放记录,song.PlayCount++,
            boolean songRegister= songDao.addPlayCount(songId);
            //记录播放数据
            boolean playCountRegister =playCountDao.insertPlayCount(userId, songId);
            //都成功->返回成功结果
            return (songRegister&&playCountRegister)? Result.success("播放量增加成功", null)
                    : Result.fail("播放量增加失败", null);
        }
        return Result.fail("播放量增加失败", null);
    }

}
